package com.vidmt.api.modules.sys.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vidmt.api.common.utils.CommUtil;
import com.vidmt.api.common.utils.FileUtil;
import com.vidmt.api.modules.sys.Enums.FileType;

public class ResUtil {
	private static Logger log = LoggerFactory.getLogger(ResUtil.class);
	public static final String USER_FILES_DIR = "userfiles";

	public static String buildUserDir(Long uid) {
		return String.format("/%s/%d/%d", USER_FILES_DIR, uid / 100000, uid);
	}

	public static String buildResDir(FileType type, Long uid) {
		return buildUserDir(uid) + "/" + type.name().toLowerCase();
	}
	// public static File buildFileDir(String relPath) {
	// return new File(getStaticDir(), relPath);
	// }

	public static String buildFilePath(FileType type, Long uid, String fileName) {
		return buildResDir(type, uid) + "/" + fileName;
	}

	public static String buildFileSavePath(FileType type, Long uid, String fileName) {
		String ext = FileUtil.getExt(fileName);
		String relPath = buildResDir(type, uid) + "/" + VUtil.time14() + CommUtil.randInt(8);
		if (!CommUtil.isEmpty(ext)) {
			relPath += ("." + ext);
		}

		return relPath;
	}
}
